package com.jh.paymentchannel.pojo.freeQuick;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jh.paymentchannel.pojo.enums.ChannelTag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.listener.ChannelTopic;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

import static org.inferred.freebuilder.shaded.org.apache.commons.lang3.StringUtils.isEmpty;

/**
 * 畅捷交易记录表
 */
@Entity
@Table(name = "t_passageway_order")
public class FreeQuickOrder implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Column(name="id")
    private int id;

    //@Transient
    @Column(name = "user_id")
    private String userId;

    /**
     * 请求流水号
     */
    @Column(name = "request_no")
    private String requestNo;

    /**
     * 商户订单号
     */
    @Column(name = "merchant_no")
    private String merchantNo;

    /**
     * 渠道产品编码
     */
    @Column(name = "channel_product_code")
    private String channelProductCode;

    /**
     * 银行卡号
     */
    @Column(name = "bank_card_no")
    private String bankCardNo;

    /**
     * 金额
     */
    @Column(name = "amount")
    private String amount;


    /**
     * 信用卡背面字
     */
    @Column(name = "cvn2")
    private String cvn2;

    /**
     * 过期日期
     */
    @Column(name = "expired")
    private String expired;

    /**
     * 产品名称
     */
    @Column(name = "product_name")
    private String productName;

    /**
     * 产品描述
     */
    @Column(name = "product_desc")
    private String productDesc;

    /**
     * 服务回调地址
     */
    @Column(name = "server_callback_url")
    private String serverCallbackUrl;

    /**
     * 返回编码
     * 200表示成功
     * 其他-表示失败 此字段是通信标识，非业务标识，业务是否 成功需要查看status判断
     */
    @Column(name="code")
    private String code;

    /**
     * 返回信息
     * 成功返回“操作成功”,失败返回错误原因
     */
    @Column(name="biz_msg")
    private String bizMsg;

    /**
     * 描述信息
     * 1代表请求未抛异常
     */
    @Column(name="biz_code")
    private String bizCode;

    /**
     * 交易入口
     * 1:在线收款，2：代还
     */
    @Column(name = "pay_type")
    private String payType;

    /**
     * 通道类型
     * 1：商旅，2：新无卡101，3：新无卡102
     */
    @Column(name = "channel_type")
    private String channelType;

    @Column(name = "create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Column(name = "update_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;


    /**
     * 用户费率
     */
    @Column(name = "rate")
    private BigDecimal rate = new BigDecimal("0.00");

    /**
     * 用户输入金额
     */
    @Column(name = "in_amount")
    private BigDecimal inAmount = new BigDecimal("0.00");

    /**
     * 推荐人id
     */
    @Column(name = "pre_user_id")
    private String preUserId;

    /**
     * 通道类型
     */
    @Column(name="channel_tag")
    private String channelTag;

    /**
     * 推荐人费率
     */
    @Column(name = "grade_rate")
    private BigDecimal gradeRate;

    /**
     * 推荐人得到分润
     */
    @Column(name = "grade_amount")
    private BigDecimal gradeAmount;

    /**
     * 贴牌商得到分润
     */
    @Column(name = "brand_amount")
    private BigDecimal brandAmount;

    /**
     * 贴牌上userId
     */
    @Column(name = "brand_user_id")
    private String brandUserId;

    /**
     * 贴牌商费率
     */
    @Column(name = "brand_rate")
    private BigDecimal brandRate;

    /**
     * 交易状态0:待交易,1：成功，2：失败，3：异常,4：交易中；
     */
    @Column(name = "pay_status")
    private String payStatus;

    /**
     * 客户端P地址
     */
    @Column(name = "client_ip")
    private String clientIp;

    /**
     * 交易城市
     */
    @Column(name = "area")
    private String area;

    /**
     * 回调状态
     */
    @Transient
    private Integer feeStatus;

    @Transient
    private String bindStatus;

    @JsonIgnore
    private transient String content;

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(String payStatus) {
        this.payStatus = payStatus;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getRequestNo() {
        return requestNo;
    }

    public void setRequestNo(String requestNo) {
        this.requestNo = requestNo;
    }

    public String getMerchantNo() {
        return merchantNo;
    }

    public void setMerchantNo(String merchantNo) {
        this.merchantNo = merchantNo;
    }

    public String getChannelProductCode() {
        return channelProductCode;
    }

    public void setChannelProductCode(String channelProductCode) {
        this.channelProductCode = channelProductCode;
    }

    public String getBankCardNo() {
        return bankCardNo;
    }

    public void setBankCardNo(String bankCardNo) {
        this.bankCardNo = bankCardNo;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getCvn2() {
        return cvn2;
    }

    public void setCvn2(String cvn2) {
        this.cvn2 = cvn2;
    }

    public String getExpired() {
        return expired;
    }

    public void setExpired(String expired) {
        this.expired = expired;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductDesc() {
        return productDesc;
    }

    public void setProductDesc(String productDesc) {
        this.productDesc = productDesc;
    }

    public String getServerCallbackUrl() {
        return serverCallbackUrl;
    }

    public void setServerCallbackUrl(String serverCallbackUrl) {
        this.serverCallbackUrl = serverCallbackUrl;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getBizMsg() {
        return bizMsg;
    }

    public void setBizMsg(String bizMsg) {
        this.bizMsg = bizMsg;
    }

    public String getBizCode() {
        return bizCode;
    }

    public void setBizCode(String bizCode) {
        this.bizCode = bizCode;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    public String getChannelType() {
        return channelType;
    }

    public void setChannelType(String channelType) {
        this.channelType = channelType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public BigDecimal getInAmount() {
        return inAmount;
    }

    public void setInAmount(BigDecimal inAmount) {
        this.inAmount = inAmount;
    }

    public String getPreUserId() {
        return preUserId;
    }

    public void setPreUserId(String preUserId) {
        this.preUserId = preUserId;
    }

    public BigDecimal getGradeRate() {
        return gradeRate;
    }

    public void setGradeRate(BigDecimal gradeRate) {
        this.gradeRate = gradeRate;
    }

    public BigDecimal getGradeAmount() {
        return gradeAmount;
    }

    public void setGradeAmount(BigDecimal gradeAmount) {
        this.gradeAmount = gradeAmount;
    }

    public String getChannelTag() {
        return channelTag;
    }

    public void setChannelTag(String channelTag) {
        this.channelTag = channelTag;
    }

    public Integer getFeeStatus() {
        return feeStatus;
    }

    public void setFeeStatus(Integer feeStatus) {
        this.feeStatus = feeStatus;
    }

    public String getBindStatus() {
        return bindStatus;
    }

    public void setBindStatus(String bindStatus) {
        this.bindStatus = bindStatus;
    }

    public BigDecimal getBrandAmount() {
        return brandAmount;
    }

    public void setBrandAmount(BigDecimal brandAmount) {
        this.brandAmount = brandAmount;
    }

    public String getBrandUserId() {
        return brandUserId;
    }

    public void setBrandUserId(String brandUserId) {
        this.brandUserId = brandUserId;
    }

    public BigDecimal getBrandRate() {
        return brandRate;
    }

    public void setBrandRate(BigDecimal brandRate) {
        this.brandRate = brandRate;
    }

    public String ofChannelTag() {
        return ChannelTag.of(getChannelTag());
    }

    @Override
    public String toString() {
        return "FreeQuickOrder{" +
                "id='" + id + '\'' +
                ", userId='" + userId + '\'' +
                ", requestNo='" + requestNo + '\'' +
                ", merchantNo='" + merchantNo + '\'' +
                ", channelProductCode='" + channelProductCode + '\'' +
                ", bankCardNo='" + bankCardNo + '\'' +
                ", amount='" + amount + '\'' +
                ", cvn2='" + cvn2 + '\'' +
                ", expired='" + expired + '\'' +
                ", productName='" + productName + '\'' +
                ", productDesc='" + productDesc + '\'' +
                ", serverCallbackUrl='" + serverCallbackUrl + '\'' +
                ", code='" + code + '\'' +
                ", bizMsg='" + bizMsg + '\'' +
                ", bizCode='" + bizCode + '\'' +
                ", payType='" + payType + '\'' +
                ", channelType='" + channelType + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", rate=" + rate +
                ", inAmount=" + inAmount +
                ", preUserId='" + preUserId + '\'' +
                ", channelTag='" + channelTag + '\'' +
                ", gradeRate=" + gradeRate +
                ", gradeAmount=" + gradeAmount +
                ", brandAmount=" + brandAmount +
                ", brandUserId='" + brandUserId + '\'' +
                ", brandRate=" + brandRate +
                ", payStatus='" + payStatus + '\'' +
                ", feeStatus=" + feeStatus +
                ", bindStatus='" + bindStatus + '\'' +
                ", content='" + content + '\'' +
                '}';
    }

    public void emptyToString() {
        if (isEmpty(getUserId())) setUserId("");
        if (isEmpty(getRequestNo())) setRequestNo("");
        if (isEmpty(getMerchantNo())) setMerchantNo("");
        if (isEmpty(getChannelProductCode())) setChannelProductCode("");
        if (isEmpty(getBankCardNo())) setBankCardNo("");
        if (isEmpty(getAmount())) setAmount("0.00");
        if (isEmpty(getCvn2())) setCvn2("");
        if (isEmpty(getExpired())) setExpired("");
        if (isEmpty(getProductName())) setProductName("");
        if (isEmpty(getProductDesc())) setProductDesc("");
        if (isEmpty(getServerCallbackUrl())) setServerCallbackUrl("");
        if (isEmpty(getCode())) setCode("");
        if (isEmpty(getBizMsg())) setBizMsg("");
        if (isEmpty(getBizCode())) setBizCode("");
        if (isEmpty(getPayType())) setPayType("");
        if (isEmpty(getChannelType())) setChannelType("");
        if (null == getCreateTime()) setCreateTime(Calendar.getInstance().getTime());
        if (null == getUpdateTime()) setUpdateTime(Calendar.getInstance().getTime());
        if (isEmpty(getPreUserId())) setPreUserId("");
        if (isEmpty(getChannelTag())) setChannelTag("");
        if (isEmpty(getBrandUserId())) setBrandUserId("");
        if (isEmpty(getPayStatus())) setPayStatus("");
        if (isEmpty(getBindStatus())) setBindStatus("");
        if (isEmpty(getContent())) setContent("");
        if (null == getFeeStatus()) setFeeStatus(0);
        if (null == getGradeRate()) setGradeRate(new BigDecimal("0.00"));
        if (null == getGradeAmount()) setGradeAmount(new BigDecimal("0.00"));
        if (null == getBrandAmount()) setBrandAmount(new BigDecimal("0.00"));
        if (null == getBrandRate()) setBrandRate(new BigDecimal("0.00"));
    }
}
